package com.changgou.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stp")
public class blogSyController {

    @Autowired
    private RestTemplate restTemplate;

    public static final String REST_URL_PROD ="http://BIGDATA";

    @RequestMapping("/getzytp")
    @ResponseBody
    public List<?> getzytp(){
        return  restTemplate.getForObject(REST_URL_PROD+"/syc/getblogtp",List.class);
    }


    @RequestMapping("/uploudimg")
    public String uploudimg(HttpServletRequest request, MultipartFile file, Map<String, Object> map){
        String ext = request.getParameter("ext");
        String fname = request.getParameter("name");
        map.put("fname",fname);
        map.put("ext",ext);
        map.put("flies",file);
        System.out.println(map);
        String sasd=   restTemplate.postForObject(REST_URL_PROD+"/syc/uploadFilerePath",map,String.class);
        System.out.println(sasd);
        return  sasd ;
    }

    @RequestMapping("/saveFileData")
    @ResponseBody
    public boolean saveFileData(@RequestBody Map<String,Object> map){
        return  restTemplate.postForObject(REST_URL_PROD+"/syc/addblogtp",map,boolean.class);
    }

    @RequestMapping("/delFileData")
    @ResponseBody
    public boolean delFileData(@RequestBody Map<String,Object> map){
        return  restTemplate.postForObject(REST_URL_PROD+"/syc/delbolgtp",map,boolean.class);
    }

}
